---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table3.log
  log type:  text
 opened on:  17 Aug 2020, 11:17:47

. 
. use "$path/nc_dataset.dta" if new_reg == 0, clear

. 
. drop black white hispanic othernw new_reg noid_p_2016 dem rep

. 
. // drop 2018 
. drop if inlist(election, 11, 12)
(13,254,638 observations deleted)

. 
. sort id election

. 
. replace voted = 0 if voted == .
(0 real changes made)

. 
. // replace voted with NA if under 18 / ineligible in that election year 
. drop if birth_year > 1998 & birth_year < 9999
(70 observations deleted)

. replace voted = . if (birth_year > 1990 & birth_year < 9999) & (election == 1 | election == 2) // 2008
(1,102,090 real changes made, 1,102,090 to missing)

. replace voted = . if (birth_year > 1992 & birth_year < 9999) & (election == 3 | election == 4) // 2010
(680,176 real changes made, 680,176 to missing)

. replace voted = . if (birth_year > 1994 & birth_year < 9999) & (election == 5 | election == 6) // 2012
(269,954 real changes made, 269,954 to missing)

. replace voted = . if (birth_year > 1996 & birth_year < 9999) & (election == 7 | election == 8) // 2014
(314 real changes made, 314 to missing)

. 
. ** create string encoding of possible pre-treatment outcome paths
. tostring voted, generate(outcome_path)
outcome_path generated as str1

. 
. by id: gen outcome_path_pretreat = outcome_path[1] + outcome_path[2] + ///
>                                                                 outcome_path[3] + outcome_path[4] + ///
>                                                                 outcome_path[5] + outcome_path[6] + ///
>                                                                 outcome_path[7] + outcome_path[8] 

. 
. gen count = 1

. 
. // keep general only
. keep if mod(election,2) == 0
(33,136,560 observations deleted)

. 
. replace voted = 0 if voted == .
(1,026,267 real changes made)

. 
. // construct age bins, give young voters who are ineligible for some election their own age bin
. gen age_bin = 11 if (birth_year > 1990 & birth_year < 9999)
(30,381,335 missing values generated)

. replace age_bin = 12 if (birth_year > 1992 & birth_year < 9999)
(1,700,440 real changes made)

. replace age_bin = 13 if (birth_year > 1994 & birth_year < 9999)
(674,885 real changes made)

. replace age_bin = 14 if (birth_year > 1996 & birth_year < 9999)
(785 real changes made)

. // give those who are eligible over the whole period their own age decile
. xtile age_decile = birth_year if (birth_year <= 1990), nq(10)

. replace age_bin = age_decile if (birth_year <= 1990)
(30,334,280 real changes made)

. drop age_decile

. 
. compress
  variable count was float now byte
  variable age_bin was float now byte
  (198,819,360 bytes saved)

. 
. bysort age_bin: sum birth_year

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 1

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  3,052,625    1932.718    5.835713       1910       1940

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 2

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  3,225,765    1944.876    2.279578       1941       1948

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 3

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  3,152,175    1951.585    1.707097       1949       1954

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 4

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  2,951,180     1957.03    1.409983       1955       1959

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 5

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  3,123,925    1962.006    1.411924       1960       1964

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 6

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  2,961,805    1967.012    1.422752       1965       1969

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 7

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  2,936,230    1971.908     1.41961       1970       1974

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 8

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  3,235,670    1977.528    1.707353       1975       1980

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 9

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  2,769,645    1983.009    1.416625       1981       1985

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 10

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  2,925,260    1988.034    1.417787       1986       1990

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 11

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  1,054,785    1991.495    .4999746       1991       1992

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 12

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |  1,025,555    1993.493    .4999561       1993       1994

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 13

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |    674,100    1995.421     .493653       1995       1996

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = 14

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |        785    1997.306    .4610107       1997       1998

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> age_bin = .

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
  birth_year |          0


. 
. sort id election

. 
. * vanilla diff in diff
. reghdfe voted treat, a(id election) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,136,560
Absorbing 2 HDFE groups                           F(   1,6627311) =   21244.21
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.6024
                                                  Adj R-squared   =     0.5030
                                                  Within R-sq.    =     0.0007
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3511

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1191366   .0008174  -145.75   0.000    -.1207386   -.1175346
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
    election |            4               5              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b1 = _b[treat]

. local se1 = _se[treat]

. local n1 = e(N)

. local nclust1 = e(N_clust)

. 
. * race by year
. reghdfe voted treat, a(id race_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,136,560
Absorbing 2 HDFE groups                           F(   1,6627311) =   22115.03
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.6034
                                                  Adj R-squared   =     0.5042
                                                  Within R-sq.    =     0.0008
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3507

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1222922   .0008223  -148.71   0.000     -.123904   -.1206805
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
race_by_year |           24              25              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b2 = _b[treat]

. local se2 = _se[treat]

. local n2 = e(N)

. local nclust2 = e(N_clust)

. 
. * age by year 
. reghdfe voted treat, a(id age_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,089,505
Absorbing 2 HDFE groups                           F(   1,6617900) =   15977.82
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.6193
                                                  Adj R-squared   =     0.5241
                                                  Within R-sq.    =     0.0006
Number of clusters (id)      =  6,617,901         Root MSE        =     0.3436

                             (Std. Err. adjusted for 6,617,901 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1060795   .0008392  -126.40   0.000    -.1077244   -.1044347
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6617901        6617901 *   | 
 age_by_year |          444             445              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b3 = _b[treat]

. local se3 = _se[treat]

. local n3 = e(N)

. local nclust3 = e(N_clust)

. 
. * age by race by year
. reghdfe voted treat, a(id race_by_age_by_year) cluster(id)
(dropped 20 singleton observations)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,089,485
Absorbing 2 HDFE groups                           F(   1,6617896) =   14302.02
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.6204
                                                  Adj R-squared   =     0.5255
                                                  Within R-sq.    =     0.0005
Number of clusters (id)      =  6,617,897         Root MSE        =     0.3431

                             (Std. Err. adjusted for 6,617,897 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.1011849   .0008461  -119.59   0.000    -.1028432   -.0995266
------------------------------------------------------------------------------

Absorbed degrees of freedom:
----------------------------------------------------------------------+
        Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
--------------------+-------------------------------------------------|
                 id |            0         6617897        6617897 *   | 
race_by_age_by_year |         2179            2180              1     | 
----------------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b4 = _b[treat]

. local se4 = _se[treat]

. local n4 = e(N)

. local nclust4 = e(N_clust)

. 
. preserve

. 
. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election)

. 
. *** get N by path by summing together n treated and n control
. by outcome_path: gen tot_tmp = count[6] if _n==6
(2,941 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path)

. by outcome_path: replace tot_tmp = count[1] if _n == 1
(341 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  3250

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 870 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,730
Absorbing 2 HDFE groups                           F(   1, 218487) =     789.35
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6412
                                                  Adj R-squared   =     0.6408
                                                  Within R-sq.    =     0.0036
                                                  Root MSE        =     0.2669

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0320634   .0011412   -28.10   0.000    -.0343002   -.0298266
-------------+----------------------------------------------------------------
    Absorbed |    F(241, 218487) =   1616.897   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          238             238              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b5 = _b[no_dmv_match]

. local se5 = _se[no_dmv_match]

. local n5 = N

. local nclust5 = N_voters

. 
. * match on pre-treatment turnout path and race
. 
. restore

. preserve

. 
. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string no_dmv_match

. by outcome_path race_string: gen tot_tmp = count[6] if _n==6
(11,833 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string)

. by outcome_path race_string: replace tot_tmp = count[1] if _n == 1
(1,549 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  12855

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path race_string)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 6845 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,570
Absorbing 2 HDFE groups                           F(   1, 217964) =     727.26
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6422
                                                  Adj R-squared   =     0.6413
                                                  Within R-sq.    =     0.0033
                                                  Root MSE        =     0.2668

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0307753   .0011412   -26.97   0.000     -.033012   -.0285386
-------------+----------------------------------------------------------------
    Absorbed |    F(604, 217964) =    646.625   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          601             601              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b6 = _b[no_dmv_match]

. local se6 = _se[no_dmv_match]

. local n6 = N

. local nclust6 = N_voters

. 
. restore

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string age_bin)

. 
. // drop if age is missing
. drop if age_bin == .
(1,755 observations deleted)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string age_bin no_dmv_match election

. by outcome_path race_string age_bin: gen tot_tmp = count[6] if _n==6
(67,314 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string age_bin)

. by outcome_path race_string age_bin: replace tot_tmp = count[1] if _n == 1
(10,022 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string age_bin)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  5
Number of records is  71615

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 10 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/10)

. gen tot_treat2 = round(tot_treat/10)

. egen op = group(outcome_path race_string age_bin)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 53965 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    209,790
Absorbing 2 HDFE groups                           F(   1, 208020) =     490.89
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6373
                                                  Adj R-squared   =     0.6342
                                                  Within R-sq.    =     0.0024
                                                  Root MSE        =     0.2681

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |   -.025942   .0011709   -22.16   0.000    -.0282369   -.0236471
-------------+----------------------------------------------------------------
    Absorbed |   F(1768, 208020) =    206.472   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |         1765            1765              0     | 
    election |            4               5              1     | 
---------------------------------------------------------------+

. local b7 = _b[no_dmv_match]

. local se7 = _se[no_dmv_match]

. local n7 = N 

. local nclust7 = N_voters

. 
. log close
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table3.log
  log type:  text
 closed on:  17 Aug 2020, 11:41:31
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
